package com.bigdata.dao;

import com.bigdata.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {

    public boolean login(String username,String password) {

        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            //1.得到连接对象
            conn=JDBCUtils.getConnection();
            String sql="select * from userinfo where uname=? and pwd=?";
            //2.创建ps对象
            ps=conn.prepareStatement(sql);
            ps.setString(1, username);
            ps.setString(2, password);
            //3.开始执行
            rs=ps.executeQuery();	//如果能成功移到下一条记录，则说明有这个用户
            return rs.next();
        } catch (SQLException e) {

            e.printStackTrace();
        }finally{
            JDBCUtils.close(conn, ps,rs);
        }
        return false;

    }
}
